//index.js

var app = getApp()
Page({
  data: {
    feed: [],
    feed_length: 0,
    jsonresult: '',
    isEmpty: false,
    user: {},
  },


  onLoad: function (options) {
    this.setData({
      user: app.globalData.user
    })

    this.getReply();
  },

  getReply: function () {
    var that = this
    wx.request({
      url: 'https://eis.natappvip.cc/ITSupport/reply_findAllReplyByUser.action',
      data: {
        'user.userId': this.data.user.userId,
      },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        let jsonresult = JSON.parse(res.data)
        console.log(jsonresult.result)
        if (jsonresult.result == "error") {
          that.setData({
            isEmpty: true,
            feed: [],
            feed_length: 0
          })
        } else {
          that.setData({
            feed: jsonresult.reply,
            feed_length: jsonresult.reply.length
          })
        }
      },
      fail: function (res) {
        console.log("failed:" & res)
      }
    })

  },

  delItem:function(e){
    var $replyId = e.currentTarget.dataset.replyId
    var that = this
    wx.showModal({
      title: '提示',
      content: '一旦删除，无法恢复，确定删除？',
      success: function (res) {
        if (res.confirm) {
          
          wx.request({
            url: 'https://eis.natappvip.cc/ITSupport/reply_delReply.action',
            data: {
              'reply.replyId': $replyId,
              'user.userId': that.data.user.userId,
            },
            header: {
              'Content-Type': 'application/json'
            },
            success: function (res) {
              let jsonresult = JSON.parse(res.data)
              console.log(jsonresult.result)
              if (jsonresult.result == "error") {

              } else {
                wx.showToast({
                  title: '删除成功',
                  icon: 'success',
                  duration: 2000
                })
                that.getReply();
              }
            },
            fail: function (res) {
              console.log("failed:" & res)
            }
        })
        } 
      }
    })
   },

      bindItemTap: function (e) {
        var $topicId = e.currentTarget.dataset.topicId
        wx.navigateTo({
          url: '../topic/topic?topicId=' + $topicId
        })
      },

})
